//
//  ListCollectionViewCell.m
//  MedicineBox
//
//  Created by dllo on 15/8/24.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "ListCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "HomeModel.h"
#import "DKNightVersion.h"
#import "UIImageView+NightImage.h"
@interface ListCollectionViewCell ()
@property (nonatomic, retain) UIImageView *drugPic;
@property (nonatomic, retain) UILabel *drugName;
@property (nonatomic, retain) UILabel *drugPrice;
@end

@implementation ListCollectionViewCell


-(void)dealloc
{
    [_drugName release];
    [_drugPic release];
    [_drugPrice release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [DKNightVersionManager addClassToSet:self.class];
        self.nightBackgroundColor = UIColorFromRGB(0x343434);
        self.drugPic = [[UIImageView alloc] init];
        [self.contentView addSubview:self.drugPic];
        [_drugPic release];
        
        self.drugName = [[UILabel alloc] init];
        [self.contentView addSubview:self.drugName];
        [_drugName release];
        
        self.drugPrice = [[UILabel alloc] init];
        [self.contentView addSubview:self.drugPrice];
        [_drugPrice release];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.drugPic.frame = CGRectMake(10, 10, self.contentView.frame.size.width - 20, self.contentView.frame.size.height - 60);
    self.drugPic.backgroundColor = [UIColor clearColor];
    self.drugPic.nightBackgroundColor = [UIColor clearColor];
    self.drugPic.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"drug" ofType:@"png"]];
    self.drugName.frame = CGRectMake(0, self.drugPic.frame.size.height + self.drugPic.frame.origin.y + 10, self.contentView.frame.size.width, 20);
    self.drugName.font = [UIFont systemFontOfSize:15];
    self.drugName.textAlignment = NSTextAlignmentCenter;
    self.drugName.textColor = [UIColor grayColor];
    self.drugName.nightTextColor = [UIColor whiteColor];
    
    self.drugPrice.frame = CGRectMake(0, self.drugName.frame.size.height + self.drugName.frame.origin.y + 5, self.contentView.frame.size.width, 20);
    self.drugPrice.textColor = [UIColor redColor];
    
}

- (void)valueWithModel:(HomeModel *)listModel
{
    if ([listModel.titleimg isEqualToString:@""]) {
        self.drugPic.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"drug" ofType:@"png"]];
    }else
    {
        [self.drugPic sd_setImageWithURL:[NSURL URLWithString:listModel.titleimg]];
    }
    self.drugName.text = listModel.namecn;
    
    float price = [listModel.avgprice floatValue];
    if (price == 0) {
        self.drugPrice.text = @"暂无报价";
    }else
    {
        self.drugPrice.text = [NSString stringWithFormat:@"￥%0.2f",price];
    }
}




@end
